<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>故障处理流程</title>
    <link href="css/layui.css" rel="stylesheet" type="text/css" />
    <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <form class="layui-form" action="" lay-filter="addForm">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <p class="title-row"> 故障处理流程</p>
                            <p class="layadmin-font-em">应急故障点<span class="fault-point-name"
                                    style="margin-left: 20px; color: burlywood;"></span></p>
                        </div>

                        <div class="layui-card-header">
                            <h3 class="title-row">专业状态选择</h3>
                        </div>
                        <div class="layui-card-body">
                            <div class="layui-form-item proBox">
                                <div style="color: #fff; text-align: center; margin:30px 0;" >
                                    <input type="checkbox" name="state" title="车辆" lay-filter="cOne" class="cOne"
                                        value="9">
                                    <input type="checkbox" name="state" title="供电" lay-filter="cOne" class="cOne"
                                        value="10">
                                    <input type="checkbox" name="state" title="通号" lay-filter="cOne" class="cOne"
                                        value="11">
                                    <input type="checkbox" name="state" title="工务" lay-filter="cOne" class="cOne"
                                        value="12">
                                    <input type="checkbox" name="state" title="物后" lay-filter="cOne" class="cOne"
                                        value="13">
                                </div>
                            </div>
                        </div>
                        <div class="layui-card-header">
                            <h3 class="title-row">维保现象填写</h3>
                        </div>
                        <div class="layui-card-body">
                            <div class="layui-form-item layui-form-text textBox">
                                <textarea name="desc" placeholder="请输入故障现象" class="layui-textarea"
                                    lay-verify="required|flowTextLength"></textarea>
                            </div>

                            <div class="layui-form-item">
                                <div class="layui-input-block sumitBtn">
                                    <button class="layui-btn confirmButton" lay-submit lay-filter="formSubmit"
                                        type="button">确认</button>
                                    <button type="reset" class="layui-btn layui-btn-primary closePage"
                                        type="button">取消</button>
                                </div>
                            </div>
                        </div>
                    </div>

                </form>
                <div class="fakeTable" style="display: none;">
                    <table class="layui-hide" id="fakeTable" lay-filter="fakeTable"></table>
                </div>
            </div>
        </div>
    </div>
    <script src="layui.js"></script>
    <script src="index.js"></script>
    <script>

        //一般直接写在一个js文件中
        layui.use(['layer', 'form'], function () {
            var layer = layui.layer
                , $ = layui.$
                , form = layui.form;

            //下拉框非空验证
            form.verify({
                flowTextLength: function (value) {
                    let i,sum;
                    sum=0;
                    for(i=0;i<value.length;i++){
                        if ((value.charCodeAt(i)>=0) && (value.charCodeAt(i)<=255)){
                            sum=sum+1;
                        } else {
                            sum=sum+2;
                        }
                    }
                    if (sum > 200) {
                        return '维保现象最多只能200个字符或者100个中文字';
                    }
                }
            });

            var faultContent = getValue("faultContent");

            form.val("addForm",{
                "desc": faultContent
            })

            var paramData = getFlowData();
            $('.fault-point-name').text(paramData.faultId);



            $('.closePage').on('click', function () {
                closeSonPage();
            });

            form.on('submit(formSubmit)', function (data) {
                

                if ($(".cOne:checked").length < 1) {
                    alertMsg('请选择专业');
                    return;
                }

                var ids = [];

                $('input[type=checkbox]:checked').each(function () {
                    ids.push($(this).val());
                });
                if(!$(this).attr('lock')){
                    $(this).attr('lock',true);
                    $.ajax({
                        url: getIP() + '/flowLink/addFaultFlowLink',
                        type: 'post',
                        // data: { faultId: paramData.faultId, flowLinkId: paramData.tag, choice: "delete" },

                        data: { faultId: paramData.faultId, faultContent: data.field.desc, flowLinkIds: ids ,faultTime:paramData.faultTime},
                        contentType: 'application/x-www-form-urlencoded',
                        success: function (data) {
                            if (data.code == 'success') {
                                layer.msg(data.msg, { time: 900, icon: 6 }, function () {
                                    window.parent.refreshAddFormData();
                                    layer.closeAll();
                                    closeSonPage();
                                    //layer.closeAll('page');
                                });//失败的表情5 成功的表情6
                                return;
                            } else {
                                layer.msg(data.msg, { icon: 5 });//失败的表情5 成功的表情6
                                return;
                            }
                        },
                    });
                    $(this).attr('lock',false);
                }
                return false;
            });

        

        });
        function closeSonPage() {
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);//关闭当前页
        }



    </script>
</body>

</html>